$package('jeecg.TostHrBirgiftinfo');
createtab=function(){
	$('#okbir').dialog('open');
	$.ajax({
		url: "queryBymonthbir.do",
		dataType:'json',
		success:function (result){
			var str = "";
			vtotal = result.total;
			if(vtotal>0){
				for(var i=0;i<vtotal;i++){
					var vdata = result.data[i];
					if(i==0)
						str+="<tr>";
					str+="<td><input type='checkbox' checked='checked' name='hrId' id='hrId' value='"+vdata.id+"#"+vdata.hrPositivetime+"'>"+vdata.hrName+"("+vdata.hrDepart+")</td>";
					if((i+1)%5!=0&&(i+1)==vtotal)
						str+="</tr>";
					if((i+1)%5==0)
						str+="</tr><tr>";
				}
				document.getElementById('peasonbri').innerHTML=str;
			}
		}
	});
}
deltetab=function(){
	$('#okbir1').dialog('open');
}

$("#hrselect").ready(function (){
	$.ajax({
		url:urls['msUrl']+"tostHrBaseinfo/hrIdList.do",
		dataType:'json',
		success:function(result){
			var str="<option></option>";
			for(var i=0;i<result.total;i++){
				str+="<option value='"+result.data[i].id+"'>"+result.data[i].hrName+"</option>";
			}
			document.getElementById("hrselect").innerHTML=str;
		}
	});
});	

jeecg.TostHrBirgiftinfo = function(){
	var _box = null;
	var _this = {
		toList:function(parentId){
				_box.form.search.resetForm();
				if(parentId){
					$('#search_parentId').val(parentId);
					$('#btnback').linkbutton('enable');
					_box.grid.datagrid('hideColumn','childMenus');
				}else{
					$('#btnback').linkbutton('disable');
					$('#btnback').linkbutton('disable');
					_box.grid.datagrid('showColumn','childMenus');
				}
				_box.handler.refresh();
		},
		//设置默认按钮数据
		addDefBtns:function(){
			var defaultBtns= [
				{"btnName":"添加","menuid":2,"actionUrls":"save.do","btnType":"add"},
				{"btnName":"修改","menuid":2,"actionUrls":"getId.do|save.do","btnType":"edit"},
				{"btnName":"删除","menuid":2,"actionUrls":"delete.do","btnType":"remove"},
			];
			var tbline = $(".tb-line:visible");
			var btnType = $("input[name='btnType']",tbline);
			$.each(defaultBtns,function(i,btn){
				var isExists = false;
				//判断按钮类型是否存在
				if(btnType.length > 0){
					for(var i =0; i < btnType.length; i++){
						if(btnType.eq(i).val() == btn.btnType){
							isExists = true;
							break;
						}
					}
				}
				if(!isExists){
					_this.addLine(btn);
				}
			});
		},
		addLine: function(data){
			var table = $("#btn-tb");
			var	html = "<tr class='tb-line'>";
			html+=	   "	<td align='center'><span  class='newFlag red'>*</span></td>";
			html+=	   "	<td><input name=\"btnName\" class=\"easyui-validatebox text-name\" style=\"width:100%\" data-options=\"required:true\"></td>";
			html+=	   "	<td><input name=\"btnType\" class=\"easyui-validatebox text-name\" style=\"width:100%\" data-options=\"required:true\"></td>";
			html+=	   "	<td><input name=\"actionUrls\" class=\"easyui-validatebox text-desc\" style=\"width:100%\"  ></td>";
			html+=	   "	<td align='center'><a class=\"easyui-linkbutton remove-btn\"  iconCls=\"icon-remove\" plain=\"true\"></a>";
			html+=	   "	<input class=\"hidden\" name=\"btnId\">";
			html+=	   "	<input class=\"hidden\" name=\"deleteFlag\">";
			html+=	   "	</td>";
			html+=	   "</tr>";
			var line = $(html);
			//版定删除按钮事件
			$(".remove-btn",line).click(function(){
				jeecg.confirm('Confirm','Are you sure you want to delete record?',function(r){
					if(r){
						_this.delLine(line);
					}
				})
			});
			if(data){
				if(data.id){
					$(".newFlag",line).html(''); //清空新增标记
				}
				$("input[name='btnId']",line).val(data.id);
				$("input[name='btnName']",line).val(data.btnName);
				$("input[name='btnType']",line).val(data.btnType);
				$("input[name='actionUrls']",line).val(data.actionUrls);
			}
			$.parser.parse(line);//解析esayui标签
			table.append(line);
			
		},
		//删除全部
		delAllLine:function(b){
			if(b){
				$(".tb-line").remove();
			}else{
				$(".tb-line").each(function(i,line){
					_this.delLine($(line));
				});
			}
		},
		//删除单行
		delLine:function(line){
			if(line){
				var btnId = $("input[name='btnId']",line).val();
				if(btnId){
					$("input[name='deleteFlag']",line).val(1); //设置删除状态
					line.fadeOut();
				}else{
					line.fadeOut("fast",function(){
						 $(this).remove();
					});
				}
			}
		},
		config:{
  			action:{
  				save:'', //新增&修改 保存Action  
  				getId:'',//编辑获取的Action
  				delele:''//删除数据的Action
  			},
  			event:{
  				add : function(){
  					_this.delAllLine(true);//清空已有的数据
  					_box.handler.add();//调用add方法
					var parentId =$('#search_parentId').val();
					if(parentId){
						$("#edit_parentId").val(parentId);
					}
				},
				edit:function(){
					_this.delAllLine(true);
					_box.handler.edit(function(result){
					  if(result!=null && typeof(result.data.btns)!= "undefined"){
						$.each(result.data.btns,function(i,btn){
							_this.addLine(btn);
						});
					  }
					});
				}
  			},
  			dataGrid:{
  				title:'生日礼金清单',
	   			url:'dataList.do',
	   			columns:[[ 
                    {field:'id',title:'全选',checkbox:true},
                    {field:'hrCode',title:'员工编号',width:60,sortable:true}, /**/     
					//{field:'hrId',title:'基础信息编号',width:80,sortable:true},				
					{field:'hbrName',title:'姓名',width:50,sortable:true},				
					//{field:'hbrCompany',title:'所在公司',width:70,sortable:true},				
					//{field:'hbrDepart',title:'部门',width:50,sortable:true},				
					{field:'hbrDatebirth',title:'出生日期',width:70,sortable:true},				
					//{field:'hbrGrade',title:'职务等级',width:60,sortable:true},				
					//{field:'hbrPositive',title:'是否转正',width:60,sortable:true},				
					{field:'hbrSalary',title:'金额',width:50,sortable:true},				
					//{field:'hbrDesc',title:'备注',width:50,sortable:true},				
					{field:'hbrMonth',title:'发放月份',width:60,sortable:true}				
				]],
				toolbar:[
                    {id:'',text:'设置发放礼金',btnType:'createtab',handler:createtab},
                    {id:'',text:'修改',btnType:'edit'},
                    {id:'',text:'删除',btnType:'remove'},
                    /*{id:'',text:'删除发放的生日礼金',btnType:'deltetab',handler:deltetab},*/
					{
                    	id:'btnback',
                    	text:'back',
                    	disabled: true,
                    	iconCls:'icon-back',
                    	handler:function(){
                    	history.back();
						}
					}
				]
			}
		},
		init:function(){
			_box = new YDataGrid(_this.config); 
			_box.init();
			$('#addLine_btn').click(_this.addLine);
			$('#addDefLine_btn').click(_this.addDefBtns);
			$('#delAllLine_btn').click(function(){
				jeecg.confirm('Confirm','Are you sure you want to delete record?',function(r){
					_this.delAllLine(false);
				});
			});			
		}
	}
	return _this;
}();

$(function(){
	jeecg.TostHrBirgiftinfo.init();
});	

//查询部门
$("#hr").combobox({
	url:urls['msUrl']+"/tostHrBirgiftinfo/queryDepartId.do",
	dataType:'json',      
	valueField:'id',
	textField:'hdpName',
	multiple:false,
	formatter:function(result){
		var s= "<span input type='hidden' class='selectId'  id='selectId_"+result.id+"'>"+result.hdpName+"</span>";
		return s;
	},
	onSelect:function(result){
		$("#selectId_"+result.id).attr("checked", true);
		document.getElementById("shrDepart").value=result.id;
		
	},
	onChange:function(){
		document.getElementById("shrDepart").value="";
    },
	onUnselect:function(result){
		$("#selectId_"+result.id).attr("checked", false);
	}
});
		function fspace(str){
		var rtstr = "";
		if (str != null) {
			for ( var i = 0; str.length > 0 && i < str.length; i++) {
			rtstr += "";
			}
		}
		return rtstr;
		}
		
		
		$(function() {        
	// 查询公司
	$('#hbrCompany').combobox({   
		 url:urls['msUrl']+"/tostHrBirgiftinfo/queryByhrCompany.do",
	            editable:true, //不可编辑状态  
	            cache: false,  
	            panelHeight: 'auto',//自动高度适合  
	            valueField:'id',     
	            textField:'paName', 
	            formatter:function(result){
	       		 var s= "<span><input type='hidden' class='selectId'  id='selectId_"+result.paValue+"' >"+result.paName+"<span>";
	       		return s;
	       	},
	       	onSelect:function(result){
	       		$("#selectId_"+result.paValue).attr("checked", true);
	       	},
	       	onUnselect:function(result){
	       		$("#selectId_"+result.paValue).attr("checked", false);
	       	}
	});
	});
		$(function() {        
			// 查询人员类别
			$('#hbrGrade').combobox({   
				 url:urls['msUrl']+"/tostHrBirgiftinfo/queryByhrhrGrades.do",
			            editable:true, //不可编辑状态  
			            cache: false,  
			            panelHeight: 'auto',//自动高度适合  
			            valueField:'id',     
			            textField:'paName', 
			            formatter:function(result){
			       		 var s= "<span><input type='hidden' class='selectId'  id='selectId_"+result.paValue+"' >"+result.paName+"<span>";
			       		return s;
			       	},
			       	onSelect:function(result){
			       		$("#selectId_"+result.paValue).attr("checked", true);
			       	},
			       	onUnselect:function(result){
			       		$("#selectId_"+result.paValue).attr("checked", false);
			       	}
			});
			});
		  
		//部门
		$("#hbrDepart").combobox({
			url:urls['msUrl']+"/tostHrBirgiftinfo/queryDepartId.do",
			cache: false,  //tostHrDepartinfo/getDepartBypost  tostHrBaseinfo
		    panelHeight: 'auto',//自动高度适合
			dataType:'json',
			valueField:'id',
			textField:'hdpName',
			multiple:false,
			formatter:function(result){
				 var s= "<span input type='hidden' class='selectId'  id='selectId_"+result.id+"'>"+result.hdpName+"</span>";
				return s;
			},
			onSelect:function(result){
				$("#selectId_"+result.id).attr("checked", true);
			},
			onUnselect:function(result){
				$("#selectId_"+result.id).attr("checked", false);
			}
		});
		
		